﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Reflection;
using System.IO;
using System.Xml.XPath;

namespace WebFabricator.org
{
    /// <summary>
    /// Used to define namespaces that uniquely identify components within the fabric so they can 
    /// be resoved without name conflicts.
    /// </summary>
    [Serializable]
    [AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface, AllowMultiple=false, Inherited =true)]
    public class NamespaceAttribute:Attribute
    {
        public Namespace @Namespace
        {
            get;
            private set;
        }

        public bool AllowMultiple
        {
            get;
            set;
        }

        public NamespaceAttribute(Type type):this(String.Format("urn:{0}",type.FullName.ToLower().Replace(".",":")))
        {
    
        }

        public NamespaceAttribute(String urn)
        {
            Namespace @namespace;
            if (Namespace.TryCreate(urn, out @namespace))
            {
                @Namespace = @namespace;
            }
            else
                throw new InvalidOperationException("invalid Namespace attribute");
            AllowMultiple = false;
        }

        public NamespaceAttribute(Uri url):this(url.ToString())
        {
        }

        public override string ToString()
        {
            return @Namespace.ToString();
        }
    
    }

   
}
